package ext.tianma.masschange.datautility;

import java.io.IOException;
import java.util.Locale;

import wt.part.WTPart;
import wt.part.WTPartUsageLink;
import wt.session.SessionHelper;
import wt.util.WTException;
import wt.util.WTProperties;

import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.AbstractDataUtility;

public class MassChangeStateDataUtility extends AbstractDataUtility {
	
	private static String RESOURCE = "ext.tianma.masschange.resource.MassChangeResource";
	private static String CLASSNAME="";
	private static boolean VERBOSE = false;
	private static WTProperties wtProperties;
	private static Locale locale = null;

	static {

		try {
			CLASSNAME= MassChangeStateDataUtility.class.getName();
			wtProperties = WTProperties.getLocalProperties();
			locale = SessionHelper.manager.getLocale();
			VERBOSE = wtProperties.getProperty("ext.tianma.masschange.datautility.verbose", false);
		}
		catch (IOException ioe) {
			ioe.printStackTrace();
		}catch (Throwable throwable) {
			throw new ExceptionInInitializerError(throwable);
		}
	}
	public MassChangeStateDataUtility() {

	}
	  /**
	 *输出调试信息
	 */
	private static void outDebugInfo(String info) {
		if(VERBOSE)
			System.out.println(CLASSNAME+"......"+info);
	}	

	@Override
	public Object getDataValue(String component_id, Object obj, ModelContext mc) throws WTException {
		WTPart part = null;
		if(obj instanceof WTPartUsageLink) {
			WTPartUsageLink link = (WTPartUsageLink)obj;
			part = link.getUsedBy();
		} else if(obj instanceof WTPart){
			part = (WTPart)obj;
		}
		String state  = part.getState().getState().getDisplay();
		outDebugInfo(state);
		return state;
	}
}
